import 'package:flutter/cupertino.dart';
import 'package:todoey_flutter/models/task.dart';
import 'package:todoey_flutter/widgets/task_tile.dart';

import '../screens/task_screen.dart';

class TasksList extends StatefulWidget {
  const TasksList({super.key, required this.taskList});

  final List<Task> taskList;

  @override
  State<TasksList> createState() => _TasksListState();
}

class _TasksListState extends State<TasksList> {
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemCount: widget.taskList.length,
      itemBuilder: (context, index) => TaskTile(
        isChecked: widget.taskList[index].isDone,
        taskTitle: widget.taskList[index].name,
        checkboxCallback: (bool? checkboxState) {
          setState(() {
            widget.taskList[index].isDone = checkboxState ?? false;
          });
        },
      ),
    );
  }
}
